/*
 *  Copyright 2010 Mahbub Mozadded Sowrov.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  under the License.
 */
/*
 * TaskManagerApp.java
 */
package com.sowrov.afrigis.tools.app.timesheet_manager;

import com.sowrov.gui.window.SplashScreen;
import com.sowrov.util.logsystem.ChronicleLogger;
import com.sowrov.util.logsystem.DiskFile;
import com.sowrov.util.logsystem.LogLevel;
import javax.swing.UnsupportedLookAndFeelException;
import org.jdesktop.application.Application;
import org.jdesktop.application.SingleFrameApplication;
import java.util.EventObject;

import javax.swing.JOptionPane;
import javax.swing.UIManager;

/**
 * The main class of the application.
 */
public class TaskManagerApp extends SingleFrameApplication {

    TaskManagerView mainWindow;
    public static SplashScreen splashScreen;

    /**
     * A convenient static getter for the application instance.
     *
     * @return the instance of TaskManagerApp
     */
    public static TaskManagerApp getApplication() {
        return Application.getInstance(TaskManagerApp.class);
    } // end getApplication()

    @Override
    public final void exit(final EventObject event) {
        if (JOptionPane.showConfirmDialog(
                mainWindow.getFrame(),
                "Do you really want to exit?",
                "Exit Confirmation",
                JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
            System.exit(0);
        } // end if
    } // end exit()

    /**
     * Main method launching the application.
     *
     * @param args DOCUMENT ME!
     */
    public static void main(final String[] args) {
        ChronicleLogger.getInstance().setLevel(LogLevel.DEBUG);
        ChronicleLogger.getInstance().setDevice(new DiskFile("timesheet.debug"));
        if (args.length>0) {
            for (int i=0; i<args.length; i++) {
                if (args[i].equalsIgnoreCase("-nodebug")) {
                    ChronicleLogger.getInstance().setLevel(LogLevel.NOLOG);
                }
            }
        }
        ChronicleLogger.getInstance().logInfo("To run the applicaiton with no debug output, start with -nodebug option");
        splashScreen = new SplashScreen(null);
        splashScreen.showSplash();
        //UIManager.setLookAndFeel("com.jtattoo.plaf.mcwin.McWinLookAndFeel");
        
        TaskManagerApp app = TaskManagerApp.getApplication();
        app.startup();
    } // end main()

    /**
     * This method is to initialize the specified window by injecting resources. Windows shown in our
     * application come fully initialized from the GUI builder, so this additional configuration is not needed.
     *
     * @param root DOCUMENT ME!
     */
    @Override
    protected void configureWindow(final java.awt.Window root) {
    } // end configureWindow()

    /**
     * At startup create and show the main frame of the application.
     */
    @Override
    protected void startup() {
        mainWindow = new TaskManagerView(TaskManagerApp.this);
        show(mainWindow);
    } // end startup()
} // end TaskManagerApp
